package Views;

import Models.Location;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

class LocationTableModel extends DefaultTableModel
{
	private ArrayList<Location> locations;

	public LocationTableModel()
	{
		this.locations = new ArrayList<Location>();
	}

	public LocationTableModel(ArrayList<Location> locations)
	{
		this.locations = locations;
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Location> locations)
	{
		this.locations = locations;
		fireTableDataChanged();
	}

	public ArrayList<Location> getData()
	{
		return this.locations;
	}

	@Override
	public int getColumnCount()
	{
		return 4;
	}

	@Override
	public int getRowCount()
	{
		if(this.locations == null)
		{
			return 0;
		}
		else
		{
			return this.locations.size();
		}
	}

	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Kunde";
				break;
			case 2:
				columnName = "Adresse";
				break;
			case 3:
				columnName = "By";
				break;
		}
		return columnName;
	}

	@Override
	public Object getValueAt(int  row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.locations.get(row).getLocationNo();
				break;
			case 1:
				value = this.locations.get(row).getCustomer().getName();
				break;
			case 2:
				value = this.locations.get(row).getAddress();
				break;
			case 3:
				value = this.locations.get(row).getCity();
				break;
		}
		return value;
	}
}
